package homowork0720;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;

public class UntilProperties {
    public void PropertyOutputStream(Properties properties, String path) {
        FileOutputStream fos = null;
        try {
            fos = new FileOutputStream(path);
            properties.store(fos, null);//前一个参数代表使用输出流，后一个参数表示注释，null是空注释，此时后默认生成执行的时间

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (fos != null) {
                try {
                    fos.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }

    public void PropertyInputStream(Properties properties, String path) {
        FileInputStream fis = null;
        try {
            fis = new FileInputStream(path);
            properties.load(fis);
//            System.out.println(properties.getProperty("name"));
//            System.out.println(properties.getProperty("age"));
//            System.out.println(properties.getProperty("phone"));
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (fis != null) {
                try {
                    fis.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }


}
